package com.ucampus.controller;

import com.ucampus.entity.Article;
import com.ucampus.entity.ResponseData;
import com.ucampus.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/")
    public ResponseData getAll() {
        return articleService.getAll();
    }

    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody List<Integer> list) {
        return articleService.delete(list);
    }

    @PostMapping("/upLoad")
    public ResponseData upLoad(@RequestParam int id, @RequestBody Article article) {
        article.setUserId(id);  // 设置 userId
        return articleService.addArticle(article);
    }
    @GetMapping("/search")
    public ResponseData search(@RequestParam String keyword) {
        return articleService.search(keyword);
    }

    @GetMapping("/userPosts")
    public ResponseData getUserPosts(@RequestParam long userId) {
        return articleService.getArticlesByUserId(userId);
    }
}
